package com.yao.item;

import java.util.*;
import java.util.stream.Collectors;

public class Demo {

    private static final int num = 5000;

    public void sayHello() {
        System.out.println("Hello world!");
    }


    public static boolean checkEqual(Integer num) {
        return num == 20;
    }

    public void luckDraw() {
        // do something
        Runnable r1 = new Runnable() {
            @Override
            public void run() {
                List<Integer> ls = new ArrayList<>();
                int count = 1;
                try {
                    //随机生成
                    ls = new Random(166).ints(1, num + 1).distinct().limit(num).boxed().collect(Collectors.toList());
//                        Collections.shuffle(ls);  //打乱
                    for (int k = 0; k <= ls.size() - 1; k++) {
                        int n2 = (int) ls.get(k);
                        if (n2 >= 1 && n2 <= 3) {
                            System.out.println(Thread.currentThread().getName() + " 第" + count + "次获得一等级");
                            count++;
                        } else if (n2 >= 101 && n2 <= 200) {
                            System.out.println(Thread.currentThread().getName() + " 第" + count + "次获得二等级");
                            count++;

                        } else if (n2 >= 1000 && n2 <= 1049) {
                            System.out.println(Thread.currentThread().getName() + " 第" + count + "次获得三等级");
                            count++;
                        } else {
                            count++;
                        }
                    }
                    Thread.sleep(10);

                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }

        };
        Thread t1 = new Thread(r1);
        t1.start();

    }

    public void findNumber() {
        String[] array = {"1", "5", "33", "7", "8", "27", "5", "90", "2", "6", "25"};
        // do something
        ArrayList<Integer> arr = new ArrayList<Integer>();
        for (String s : array) {  //遍历字符串数组，转换成Integer类型数组
            arr.add(Integer.valueOf(s));

        }
        int min = Collections.min(arr); //最小值
        int max = Collections.max(arr);  //最大值
        int sum = min + max;
        System.out.println("最大值和最小值的和为：" + sum);

    }

    public static void main(String[] args) {
        Demo d = new Demo();
        d.findNumber();  //找数字
        System.out.println("--------------------------抽奖开始------------------------------");
        d.luckDraw();

    }


}

